odoo.define('web.fhbasic_fields', function (require) {
    "use strict";
	
	
var AbstractField = require('web.AbstractField');
var core = require('web.core');
var crash_manager = require('web.crash_manager');
var datepicker = require('web.datepicker');
var dom = require('web.dom');
var Domain = require('web.Domain');
var DomainSelector = require('web.DomainSelector');
var DomainSelectorDialog = require('web.DomainSelectorDialog');
var framework = require('web.framework');
var session = require('web.session');
var utils = require('web.utils');
var view_dialogs = require('web.view_dialogs');
var field_utils = require('web.field_utils');
var registry = require('web.field_registry');

var qweb = core.qweb;
var _t = core._t;
var lcontext='';
var fhclass=null;
var fhtable = AbstractField.extend({
    template: 'WebformfhtreeMain',
    events: {
        ///'blur .o_domain_show_selection_button': '_onchange',
        ///'input': '_onchange',
        ///'keyup': '_onchange',
        ///'change': '_onchange',		
    },
    init: function(parent, data){
       
        this._super.apply(this, arguments);
    },

    start: function(){		
        this._super.apply(this, arguments);	  
    },


    load: function () {
			var self = this;
            var loading_done = new $.Deferred();
            session.rpc("/web_widget_iframe/data2", {}).then(function (data) {
            //console.log('--------data:--------');
			///隐藏控件
            //console.log(self.__node.attrs.fhp_field);
			fhclass=self.attrs.name;	
			var hidden1=$("div[name="+fhclass+"]>input[name='hidden1']");
            hidden1.val(self.__node.attrs.fhp_field);
			
			var hidden2=$("div[name="+fhclass+"]>input[name='hidden2']");
            hidden2.val(self.__node.attrs.fhtree_model);			
			
			if(self.value!==false)
			{				
            //console.log('--------data:--------');
            //console.log(self.value["data"]["display_name"]);			
            //console.log(self.mode);
			if(self.mode== 'readonly')
			{
		     fhclass=self.attrs.name;			
             var table1 = $("div[name="+fhclass+"]>div:first>input[name='fhinput1']");
			 table1.attr("style", "display:none");			 
             table1.val(self.value["data"]["display_name"]);
			 
            var table2 = $("div[name="+fhclass+"]>div:nth-child(2)>span[name='fhinput2']");
			table2.attr("style","display:block");			
            table2.html(self.value["data"]["display_name"]);
			
            var table3 = $("div[name="+fhclass+"]>div:nth-child(3)>a[name='menuBtn']");
			table3.attr("style","display:none");	
			
			}				
			
			if(self.mode=='edit')
			{
		     fhclass=self.attrs.name;			
             var table1 = $("div[name="+fhclass+"]>div:first>input[name='fhinput1']");
			 table1.attr("style", "display:block");			 
             ///table1.val(self.value["data"]["display_name"]);
			 
            var table2 = $("div[name="+fhclass+"]>div:nth-child(2)>span[name='fhinput2']");
			table2.attr("style","display:block");			
            table2.html(self.value["data"]["display_name"]);	
			
			}	

		    var table1 = $("div[name="+fhclass+"]>div:first>input[name='fhinput1']");
		    table1.on("blur", self._onchange.bind(self));
			}
			else
			{
			fhclass=self.attrs.name;
		    var table1 = $("div[name="+fhclass+"]>div:first>input[name='fhinput1']");
		    table1.on("blur", self._onchange.bind(self));				
			}
			
          });
         ///return true;
        },
 
    _render: function () {

		this.load();
		
    },
  	
    _onchange: function (event) {
		var self = this;
        var loading_done = new $.Deferred();		
        //console.log('-------核心代码9999:--------');
	    fhclass=self.attrs.name;			
	    var table1 = $("div[name="+fhclass+"]>div:first>input[name='fhinput1']");
	    //console.log('--------核心代码2--------',table1.val());
        var fhvale=table1.val();
		if(fhvale!="")
		{
        var k1=fhvale.indexOf("[");
        var k2=fhvale.indexOf("]");
		fhvale=fhvale.substring(k1+1,k2);
	    self._setValue(fhvale);
	    //console.log('--------核心代码3--------',fhvale);
		}		
	 
    },



});

    registry.add('fhtable', fhtable);
    return {
        fhtable: fhtable,
    };

});
